import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class w{
    public static void main(String[] args) {
    }
}

//5543. 两个相同字符之间的最长子字符串
class Solution1 {
    public int maxLengthBetweenEqualCharacters(String s) {
        int max = -1;
        Map<Character,Integer> map = new HashMap<>();
        for(int i=0;i<s.length();i++){
            char c = s.charAt(i);
            if(map.containsKey(c)){
                max = Math.max(max, i-1-map.get(c));
            }else{
                map.put(c, i);
            }
        }
        return max;
    }
}

// 5545. 无矛盾的最佳球队
class Solution {
    class Teamer{
        int age;
        int score;
    }
    public int bestTeamScore(int[] scores, int[] ages) {
        int[] dp = new int[scores.length];
        Teamer[] ers = new Teamer[scores.length];
        for(int i=0;i<scores.length;i++){
            ers[i] = new Teamer();
            ers[i].age = ages[i];
            ers[i].score = scores[i]; 
        }   
        //排序的目的是使只需要考虑前面就可以了，不用考虑后面
        Arrays.sort(ers,new Comparator<Teamer>(){
            @Override
            public int compare(Solution.Teamer a, Solution.Teamer b) {
                if(a.age!=b.age) return a.age - b.age;
                return a.score - b.score;
            }
        });
        //最长上升子序列
        int max = 0;
        for(int i=0;i<scores.length;i++){
            int age = ers[i].age;
            int score = ers[i].score;
            int temp_max = 0;
            for(int j=i-1;j>=0;j--){
                if(ers[j].age<=age&&ers[j].score<=score) temp_max =  Math.max(temp_max, dp[j]);
            }
            dp[i] = temp_max + ers[i].score;
            max = Math.max(max,dp[i]);
        }
        return max;
    }
}